package org.alis.smallcc.designpatterns.behavior.memento;

import java.util.Stack;

import org.apache.commons.collections4.CollectionUtils;

/**
 * 看守 也是备忘录的记录书籍
 * 
 * @author luochuan
 */
public  class StackCareTaker implements CareTaker {

	/**
	 * 备忘录栈
	 */
	private Stack<Memento> stack;
	
	public StackCareTaker() {
		this.stack = new Stack<>();
	}
	
	/**
	 * 添加记录
	 */
	@Override
	public Memento pushMemento(Memento memento) {
		return stack.push(memento);
	}
	
	@Override
	public Memento popMemento() {
		if(CollectionUtils.isNotEmpty(this.stack)) {
			return this.stack.pop();
		}
		throw new UnsupportedOperationException("备忘录操作已经执行完毕");
	}
	
	
}
